package com.example.riceexambackend.common.exception;

import com.example.riceexambackend.common.errorcode.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 全局异常类
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class GlobalException extends RuntimeException {
    private Integer code; // 错误码
    private String msg; // 错误描述信息

    // 空参构造用于序列化
    public GlobalException() {}

    public GlobalException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public GlobalException(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
    }


}
